<template>
  <el-container class="container">
    <el-aside class="aside" :style="{width: collapseObj.asideWith}">
      <el-menu :collapse="isCollapse" background-color="#69a9d7" text-color="#fff" active-text-color="#ffd04b"
               style="color: white" :collapse-transition="false" router default-active="about">
        <el-menu-item index="about">
          <i class="el-icon-s-home" style="color: white"></i>
          <span slot="title">首页</span>
        </el-menu-item>
        <el-submenu index="2">
          <template slot="title">
            <i class="el-icon-s-tools" style="color: white"></i>
            <span>系统管理</span>
          </template>
          <el-menu-item-group>
            <el-menu-item index="user">用户管理</el-menu-item>
            <el-menu-item index="role">角色管理</el-menu-item>
            <el-menu-item index="dept">部门管理</el-menu-item>
          </el-menu-item-group>
        </el-submenu>
        <el-submenu index="3">
          <template slot="title">
            <i class="el-icon-box" style="color: white"></i>
            <span>商家管理</span>
          </template>
          <el-menu-item-group>
            <el-menu-item index="shop">商户列表</el-menu-item>
            <el-menu-item index="shopEdit">添加商户</el-menu-item>
            <el-menu-item index="addShop">添加商户</el-menu-item>
            <el-menu-item index="listShop">商品列表</el-menu-item>
            <el-menu-item index="foodList">食物列表</el-menu-item>
            <el-menu-item>订单管理</el-menu-item>
          </el-menu-item-group>
        </el-submenu>
      </el-menu>
    </el-aside>
    <el-main class="main">
      <el-header class="header" style="height: 56px">
        <el-row>
          <el-col :span="1" class="menu-toggle">
            <i :class="collapseObj.showMenuIcon" :title="collapseObj.iconTitle" @click="zoom"></i>
          </el-col>
          <el-col :span="6">
            <el-breadcrumb separator-class="el-icon-arrow-right" v-if="breadcrumbList.length>1">
              <el-breadcrumb-item v-for="(item,index) in breadcrumbList" :key="index" :to="{ path: item.path }">{{ item.title }}</el-breadcrumb-item>
            </el-breadcrumb>
          </el-col>
<!--          <el-col :span="6">-->
<!--            <el-breadcrumb separator-class="el-icon-arrow-right" v-if="breadcrumbList.length>1">-->
<!--              <el-breadcrumb-item v-for="(item,index) in breadcrumbList" :key="index">-->
<!--                <a v-if="item.path" :herf="'#'+item.path">{{ item.title }}</a>-->
<!--                <template v-else>{{item.title}}</template>-->
<!--                </el-breadcrumb-item>-->
<!--            </el-breadcrumb>-->
<!--          </el-col>-->
          <el-col :span="2" :offset="15" class="info">
            <el-dropdown trigger="click">
              <div class="avatar">
                <el-image style="height: 50px;width: 50px" :src="require('../assets/images/avatar.png')"
                          fit="fill"></el-image>
                <!--                <el-avatar shape="square" :src="require('../assets/images/avatar.png')" ></el-avatar>-->
              </div>
              <el-dropdown-menu>
                <el-dropdown-item>个人信息</el-dropdown-item>
                <el-dropdown-item>修改密码</el-dropdown-item>
                <hr>
                <el-dropdown-item @click.native="logout()">退出系统</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </el-col>

        </el-row>
      </el-header>
      <el-main class="content">
        <router-view></router-view>
      </el-main>
    </el-main>
  </el-container>
</template>

<script>
export default {
  name: 'Home',
  data() {
    return {
      userInfo: {},
      isCollapse: false,
      breadcrumbList: [{title: '首页', path: '/'}]
    }
  },
  watch: {
    $route() {
      this.getBreadcrumbList()
    }
  },
  computed: {
    collapseObj() {
      return {
        asideWith: this.isCollapse ? '56px' : '200px',
        showMenuIcon: this.isCollapse ? 'el-icon-s-unfold' : 'el-icon-s-fold',
        iconTitle: this.isCollapse ? '展开菜单' : '关闭菜单'
      }
    }
  },
  methods: {
    zoom() {
      this.isCollapse = !this.isCollapse
    },
    logout() {
      this.$confirm('确定突出系统吗？', {type: 'info'}).then(() => {
        this.$router.replace('login')
      })
    },
    getBreadcrumbList() {
      // 初始化数组
      this.breadcrumbList.length = 1
      if (this.$route.meta.parentTitle) {
        this.breadcrumbList.push({title: this.$route.meta.parentTitle, path: ''}, {title: this.$route.meta.title, path: this.$route.path})
      }

    }
  },
  created() {
    this.getBreadcrumbList()


  }
}
</script>
<style scoped lang="scss">
.container {
  .aside {
    height: 100vh;
    background-color: #69a9d7;

    ul {
      border: 0;
    }
  }

  .main {
    padding: 0;
    background-color: #cfe6ef;
    height: 100vh;
    overflow: hidden;

    .header {
      background-color: #72add7;

      & > div {
        height: 100%;

        & > div {
          height: 100%;
          display: flex;
          align-items: center;
          justify-content: center;

          i {
            font-size: 26px;
            color: #f6f6f6;
            cursor: pointer;
          }

          .avatar {
            height: 50px;
            width: 50px;
            border-radius: 25px;
            overflow: hidden;
            cursor: pointer;
          }
        }
      }
    }

    .content {

      background-color: #f6f6f6;
      margin: 20px;
      height: calc(100vh - 60px);
    }
  }
}
</style>
